﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>专业文献管理中心</title>
    @*--------------------应用easyUI的CSS文件---------------------*@
    <link href="~/themes/css/easyui.css" rel="stylesheet" />
    <link href="~/themes/css/icon.css" rel="stylesheet" />
    <link href="~/themes/css/Site.css" rel="stylesheet" />
    @*---------------------应用easyUI的的JS文件-----------------*@
    <script type="text/javascript" src="~/scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="~/scripts/easyui-lang-zh_CN.js"></script>
    @*修改时间格式的Js文件*@
    <script src="~/scripts/datapattern2.js"></script>
    <script src="~/scripts/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
        $(function () {
            //初始化弹出窗体
            initTable();
            //搜索文章信息
            SearchArticleInfo();
            DeleteArticleByClick();

        });

        //初始化表格 
        function initTable(queryData) {
            $('#test').datagrid({
                title: '专业文献管理',
                iconCls: 'icon-save',
                height: 500,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: '/Literature/GetAllLiterature',
                sortName: 'ID',
                sortOrder: 'asc',
                //striped:true,
                border: true,
                remoteSort: false,
                idField: 'ID',
                pagination: true,
                rownumbers: true,
                //singleSelect: true,
                queryParams: queryData,
                columns: [[
                    { field: 'ck', checkbox: true },
					{ field: 'ID', title: 'ID', width: 50, sortable: true },
					{ field: 'Title', title: '文当标题', width: 100, sortable: true },
                    //{ field: 'Category', title: '文章类别', width: 100, sorttable: true },
                    { field: 'Author', title: "作者", width: 150, sortable: true },
                    {
                        field: 'Action2', title: '操作选项', width: 80, align: 'center',
                        formatter: function (value, row, index) {
                            if (self) {
                                var u = '<a href="#" onclick="uprow(this)">修改文章</a> ';
                                return u;
                            }
                            else { alert("没有选中"); }
                        }
                    },
                    {
                        field: 'Action3', title: '操作选项', width: 80, align: 'center',
                        formatter: function (value, row, index) {
                            if (self) {
                                var d = '<a href="#" onclick="delerow(' + index + ')">删除文章</a> ';
                                return d;
                            }
                            else { alert("没有选中"); }
                        }
                    },
                    {
                        field: 'Action4', title: '操作选项', width: 80, align: 'center',
                        formatter: function (value, row, index) {
                            if (self) {
                                var a1 = '<a href="#" onclick="add1row(' + index + ')">添加附件</a> ';
                                return a1;
                            }
                            else { alert("没有选中"); };
                        }
                    },
                     {
                         field: 'Action5', title: '操作选项', width: 80, align: 'center',
                         formatter: function (value, row, index) {

                             var a2 = '<a href="#" onclick="add2row(this)">添加相关文章</a> ';
                             return a2;

                         }
                     }
                ]],
                toolbar: [
                    {
                        id: 'btnadd',
                        text: '添加文档',
                        iconCls: 'icon-add',
                        handler: function () {
                            //实现弹出添加的层
                            ShowCreateArticle();
                        }
                    }, '-', {
                        id: 'btncut',
                        text: '修改文档',
                        iconCls: 'icon-cut',
                        handler: function () {
                            //实现弹出修改信息的层
                            ShowUpdateDialog();
                        }
                    }, '-', {
                        id: 'btncut',
                        text: '添加附件',
                        iconCls: 'icon-add',
                        handler: function () {
                            //弹出添加附件
                            ShowAddDialog();
                        }
                    }, '-', {
                        id: 'btncut',
                        text: '添加相关文档',
                        iconCls: 'icon-add',
                        handler: function () {
                            //弹出添加相关文档
                            ShowAboutDialog();
                        }
                    }, '-', {
                        id: 'btnsave',
                        text: '删除文档',
                        iconCls: 'icon-remove',
                        handler: function () {
                            DeleteArticleByClick();
                        }
                    }]
                ,
                onSelect: function (rowIndex, rowData) {

                    var sele = true;
                }
            });
        }

        function getRowIndex(target) {
            var tr = $(target).closest('tr.datagrid-row');
            return parseInt(tr.attr('datagrid-row-index'));
        }
        //function lookrow(target) {
        //    $('#test').datagrid('beginEdit', getRowIndex(target));
        //}
        function uprow(target) {
            //$('#test').datagrid('beginEdit', getRowIndex(target));
            ShowUpdateDialog()
        }
        function delerow(target, index) {
            //$('#test').datagrid('selectRow', index);
            //$('#test').datagrid('selectRow', index);
            DeleteArticleByClick();
        }
        function add1row(target) {
            ShowAddDialog();
        }
        function add2row(target) {
            //$('#test').datagrid('getSelected');
            ShowAboutDialog();
        }

        //弹出文档添加页面
        function ShowCreateArticle() {
            location.href = "/AddArticle/Index";
        }

        //弹出文档修改页面
        function ShowUpdateDialog() {
            var row = $("#test").datagrid("getSelected");
            var UpdateInfoID = $("#test").datagrid("getSelections");
            if (UpdateInfoID.length == 1 || row.length == 1) {
                location.href = "/AddArticle/UpdataArticle?ID=" + UpdateInfoID[0].ID;
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }

        }

        //实现多选删除信息
        function DeleteArticleByClick() {

            var row = $('#test').datagrid('getSelected');
            var deleteID = $("#test").datagrid("getSelections");
            if (deleteID.length >= 1 || row.length == 1) {
                var ids = "";   //1,2,3,4
                for (var i = 0; i < deleteID.length; i++) {
                    ids += deleteID[i].ID + ",";
                }
                ids = ids.substring(0, ids.length - 1);

                //遍历出删除文章的信息
                var Titilelist = "";
                for (var i = 0; i < deleteID.length; i++) {
                    Titilelist += deleteID[i].Title + ",";
                }
                Titilelist = Titilelist.substring(0, Titilelist.length - 1);

                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + Titilelist + "</font>文章吗？", function (DeleteArticleInfo) {
                    if (DeleteArticleInfo) {
                        $.post("/Literature/DeleteArticleInfo", { deleteID: ids, Title: Titilelist }, function (data) {
                            if (data == "OK") {
                                $.messager.alert("友情提示", "删除成功");
                                $("#test").datagrid("reload");
                                $("#test").datagrid("clearSelections");
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "请您选择要删除的数据");
            }
        }

        //弹出添加附件
        function ShowAddDialog() {
            var row = $('#test').datagrid('getSelected');
            var InfoID = $("#test").datagrid("getSelections");
            if (InfoID.length == 1 || row.length == 1) {
                $("#AddDialog").dialog("open").dialog("setTitle", "添加附件");
            }
            else {
                $.messager.alert("友情提示", "每次只能为一篇文章添加附件，你已经选择了<font color='red' size='6'>" + InfoID.length + "</font>行");
            }
            $("#addframe").attr("src", "/Literature/FileAdd/" + InfoID[0].ID);
        }

        //添加附件成功之后自行的方法
        function AfterAdd() {
            $("#AboutDialog").dialog('close');
            $.messager.alert("友情提示", "添加附件成功");
        }

        //弹出添加相关文档
        function ShowAboutDialog() {
            var row = $('#test').datagrid('getSelected');
            var AboutID = $("#test").datagrid('getSelections');
            if (AboutID.length == 1 || row.length == 1) {
                $("#AboutDialog").dialog('open').dialog('setTitle', "添加相关文档");

            }
            else {
                $.messager.alert("友情提示", "每次只能为一篇文章添加相关文档，你已经选择了<font color='red' size='6'>" + AboutID.length + "</font>个");
            }
            //将弹出的信息修改iframe框架跳转的src属性设置为修改用户权限的信息
            $("#addframe1").attr("src", "/Literature/AboutArticle/" + AboutID[0].ID);

        }

        //添加附件成功之后自行的方法
        function AfterAdd() {
            $("#AboutDialog").dialog('close');
            $.messager.alert("友情提示", "添加附件成功");
        }
        //添加附件成功之后自行的方法
        function AfterSetAdd() {
            $("#AboutDialog").dialog('close');
            $.messager.alert("友情提示", "添加附件成功");
        }
        //搜索数据信息
        function SearchArticleInfo() {
            //btnSerach，txtCategory，txtName
            //按条件进行查询信息
            $("#btnSerach").click(function () {
                var queryData = { SearchCategory: $("#Category").combobox('getValue'), SearchName: $("#txtSerachName").val() };
                initTable(queryData);
                return false;
            });
        }

        ////弹出添加相关文档
        //function ShowLookArticle() {
        //    var AboutID = $("#test").datagrid('getSelections');
        //    if (AboutID.length == 1) {
        //        location.href = "/AddArticle/LookArticle?ID=" + AboutID[0].ID;

        //    }
        //    else {
        //        $.messager.alert("友情提示", "每次只能查看一篇文章，你已经选择了<font color='red' size='6'>" + AboutID.length + "</font>个");
        //    }
        //}

    </script>
</head>
<body>
    <fieldset style="height: 76px">
        <legend>文档查询</legend>
        <div>
            <label for="txtCategory">文章类别：</label>
            <select id="Category" name="Category" editable="false" class="easyui-combobox" style="width: 200px">
                <option value="0">专业文献</option>
                <option value="1">业务范围</option>
                <option value="2">工程实例</option>
                <option value="3">技术优势</option>
            </select>
            &nbsp;&nbsp;
            <label for="txtName">文档名称：</label>
            <input type="text" id="txtSerachName" name="txtName" />

            <a href="#" class="easyui-linkbutton" iconcls="icon-search" id="btnSerach" name="btnSerach">模糊搜索</a>
        </div>
    </fieldset>
    <div>
        <table id="test"></table>
    </div>
    @*----------------------------附加文档的弹出层--------------------------------*@
    <div id="AddDialog" class="easyui-dialog" style="width: 660px; height: 500px; padding: 10px 20px"
        closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <iframe id="addframe" src="/Welcome.htm" scrolling="yes" frameborder="0" width="100%" height="100%"></iframe>
    </div>
    @*----------------------------相关文档的弹出层--------------------------------*@
    <div id="AboutDialog" class="easyui-dialog" style="width: 760px; height: 300px; padding: 10px 20px"
        closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <iframe id="addframe1" src="/Welcome.htm" scrolling="yes" frameborder="0" width="100%" height="100%"></iframe>
    </div>
</body>
</html>

